package com.lagou.java.sqlSession;

import com.lagou.java.config.XMLConfigBuilder;
import com.lagou.java.pojo.Configration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {
        //第一:使用dom4j解析配置文件, 将解析出来的内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configration configration = xmlConfigBuilder.parseConfig(in);

        //第二: 创建sqlSessionFactory对象: 工厂类; 生产sqlSession会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configration);

        return defaultSqlSessionFactory;
    }

}
